<?php

    require_once './model/users.php';
    $md_users = new Users();
    $users = $md_users->select();
    ?>
<form method="POST">
    Username: <input type="text" name="name"><br>
    Password: <input type="password" name="password"><br>
    <input type="submit" name="submit" value="Login">
</form>
<?php
if (isset($_POST['submit'])){
    $login = array (
      'name' => $_POST['name'],  
        'password' => $_POST['password']
    );
    $flag = FALSE;
    for ($i = 0 ; $i < count($users);$i++){
        if ((strcmp($login['name'], $users[$i]['name'])==0)&&
           (strcmp(md5($login['password']), $users[$i]['password'])==0)){
            $flag= TRUE;
            break;
        }            
    }
    if ($flag){
        $_SESSION['flag'] = TRUE;
    echo 'thanh cong';
    }else {
            echo 'that bai';    
        }
        
    }

